<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
            $("#studentadd").click(function () {
                //ajax 上传文件，FormData
                //文件域和非文件的都进去了
                //$("#addForm")[0]
                let formData=new FormData(document.getElementById("addForm"));
                $.ajax({
                    cache: true,
                    type: "post",
                    url: "video/add",
                    async: false,
                    data: formData,
                    contentType: false,
                    processData: false,
                    success:function (r) {
                        alert(r.code+"<<<>>>"+r.msg);
                        //$("From").reset();
                    },
                    error:function (e) {
                        alert("错误信息是："+JSON.stringify(e));
                    }
                });
                return false;//
            });
        })
    </script>
</head>
<body>
   <h1>上传视频</h1>
<form id="addForm">
    <div class="main-container">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="title" autocomplete="off"
                       placeholder="title" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">课程名称</label>
            <div class="layui-input-block">
                <select id="courseid" name="courseid" lay-verify="required" lay-search>
                </select>
            </div>
        </div>
        <!-- 	<div class="layui-form-item">
        <label class="layui-form-label">视频地址</label>
        <div class="layui-input-block">
            <input type="text" name="url" lay-verify="title" autocomplete="off" placeholder="视频地址"
                class="layui-input">
        </div>
    </div> -->
        <div class="layui-form-item">
            <label class="layui-form-label">视频地址</label>
            <div>
                <input type="file" name="video" class="layui-btn" id="url">
                <video class="layui-upload-video" id="video" width="100" height="100"></video>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图片</label>
            <div>
                <input type="file" name="cover" class="layui-btn" id="idcoverimg">
                <img class="layui-upload-img" id="photo" width="100" height="100">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建时间</label>
            <div class="layui-input-block">
                <input type="datetime-local" name="createtime" id="createtime" lay-verify="createtime"
                       autocomplete="off" placeholder="创建时间" class="layui-input">
            </div>
        </div>

        <div class="button-container">
            <button id="studentadd" type="submit" class="pear-btn pear-btn-primary pear-btn-sm"
                    lay-submit="" lay-filter="user-save" id="studentadd">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>

        <div>
            <!-- file:///e:/temp/images/2ddd.png-->
            <img src="images/2d7a9f3e-e7c6-4c3e-a35a-6a34b5fc5d05.png"/>
        </div>
</form>
</body>
</html>